/**
 * Created by vincent on 2016/12/9.
 */
var Alert = {};
Alert.config = function (infoConfig, successConfig, errorConfig, confirmConfig, confirmButtonText, cancelButtonText) {
    Alert.infoConfig = infoConfig;
    Alert.successConfig = successConfig;
    Alert.errorConfig = errorConfig;
    Alert.confirmConfig = confirmConfig;
    Alert.confirmButtonText = confirmButtonText;
    Alert.cancelButtonText = cancelButtonText;
}
Alert.info = function (msg, title) {
    swal({
        text: msg,
        title: title || Alert.infoConfig.title,
        type: "info"
    });
};

Alert.successMessage;

Alert.success = function (msg, title) {
    Alert.successMessage = {
        text: msg || Alert.successConfig.text,
        title: title || Alert.successConfig.title,
        type: "success"
    };
    setTimeout('alertSuccess()', 500);
};

function alertSuccess() {
    swal(Alert.successMessage);
}

Alert.errorMessage;
Alert.error = function (msg, title) {
    Alert.errorMessage = {
        text: msg,
        title: title || Alert.errorConfig.title,
        type: "error"
    };
    setTimeout('alertError()', 500);
};

function alertError() {
    swal(Alert.errorMessage);
}

Alert.confirm = function (msg, title, callbackFun) {
    if (title instanceof Function) {
        callbackFun = title;
        title = Alert.confirmConfig.title
    }
    if (msg && msg instanceof Function) {
        callbackFun = msg;
        msg = Alert.confirmConfig.msg;
    }
    swal({
        text: msg || Alert.confirmConfig.msg,
        title: title || Alert.confirmConfig.title,
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55"
    }, callbackFun);
};